using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class BatchttlMap : EntityTypeConfiguration<Batchttl>
    {
        public BatchttlMap()
        {
            // Primary Key
            this.HasKey(t => t.BATCH);

            // Properties
            this.Property(t => t.BATCH)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.BATCHTYPE)
                .IsRequired()
                .HasMaxLength(2);

            this.Property(t => t.PERIOD)
                .IsRequired()
                .HasMaxLength(4);

            this.Property(t => t.SOURCE)
                .IsRequired()
                .HasMaxLength(2);

            this.Property(t => t.SUBSOURCE)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.MAINSOURCE)
                .HasMaxLength(2);

            this.Property(t => t.ACCESIBLEFROM)
                .HasMaxLength(3);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.DESC)
                .HasMaxLength(100);

            this.Property(t => t.SUBDATABASE)
                .HasMaxLength(50);

            this.Property(t => t.BatchID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.NewBatch)
                .HasMaxLength(8);

            this.Property(t => t.Sbatch)
                .HasMaxLength(8);

            this.Property(t => t.Classification)
                .HasMaxLength(20);

            this.Property(t => t.BATCHTTL_Approval)
                .IsFixedLength()
                .HasMaxLength(1);

            this.Property(t => t.BatchTTL_SourceBatch)
                .HasMaxLength(8);

            this.Property(t => t.Reverse_DocumentType)
                .HasMaxLength(20);

            this.Property(t => t.Reverse_DocumentID)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("Batchttl");
            this.Property(t => t.BATCH).HasColumnName("BATCH");
            this.Property(t => t.TOTAL).HasColumnName("TOTAL");
            this.Property(t => t.TOTALDOL).HasColumnName("TOTALDOL");
            this.Property(t => t.DEBITS).HasColumnName("DEBITS");
            this.Property(t => t.DEBITSDOL).HasColumnName("DEBITSDOL");
            this.Property(t => t.CREDITS).HasColumnName("CREDITS");
            this.Property(t => t.CREDITSDOL).HasColumnName("CREDITSDOL");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.BATCHTYPE).HasColumnName("BATCHTYPE");
            this.Property(t => t.PERIOD).HasColumnName("PERIOD");
            this.Property(t => t.CLOSING).HasColumnName("CLOSING");
            this.Property(t => t.PRNJRNL).HasColumnName("PRNJRNL");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.SOURCE).HasColumnName("SOURCE");
            this.Property(t => t.SUBSOURCE).HasColumnName("SUBSOURCE");
            this.Property(t => t.MAINSOURCE).HasColumnName("MAINSOURCE");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.ACCESIBLEFROM).HasColumnName("ACCESIBLEFROM");
            this.Property(t => t.CORRECTIVE).HasColumnName("CORRECTIVE");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.USERID).HasColumnName("USERID");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.RECURRING).HasColumnName("RECURRING");
            this.Property(t => t.SUBDATABASE).HasColumnName("SUBDATABASE");
            this.Property(t => t.Voucher).HasColumnName("Voucher");
            this.Property(t => t.BatchID).HasColumnName("BatchID");
            this.Property(t => t.NewBatch).HasColumnName("NewBatch");
            this.Property(t => t.Sbatch).HasColumnName("Sbatch");
            this.Property(t => t.Classification).HasColumnName("Classification");
            this.Property(t => t.TPI_BATCHTTL_Log).HasColumnName("TPI_BATCHTTL_Log");
            this.Property(t => t.BATCHTTL_Posted).HasColumnName("BATCHTTL_Posted");
            this.Property(t => t.BATCHTTL_Approval).HasColumnName("BATCHTTL_Approval");
            this.Property(t => t.BATCHTTL_Selected).HasColumnName("BATCHTTL_Selected");
            this.Property(t => t.BATCHTTL_Category).HasColumnName("BATCHTTL_Category");
            this.Property(t => t.BatchTTL_Reverse).HasColumnName("BatchTTL_Reverse");
            this.Property(t => t.BatchTTL_SourceBatch).HasColumnName("BatchTTL_SourceBatch");
            this.Property(t => t.Reverse_DocumentType).HasColumnName("Reverse_DocumentType");
            this.Property(t => t.Reverse_DocumentID).HasColumnName("Reverse_DocumentID");
            this.Property(t => t.BATCHTTL_CreatedON).HasColumnName("BATCHTTL_CreatedON");

            // Relationships
            this.HasOptional(t => t.Cstctr)
                .WithMany(t => t.Batchttls)
                .HasForeignKey(d => d.CSTCTRID);
            this.HasOptional(t => t.Name)
                .WithMany(t => t.Batchttls)
                .HasForeignKey(d => d.USERID);
            this.HasRequired(t => t.Period1)
                .WithMany(t => t.Batchttls)
                .HasForeignKey(d => d.PERIOD);

        }
    }
}
